package com.example.extenddemo.controller;

import com.example.extenddemo.config.RepeatSubmit;
import com.example.extenddemo.config.SpEL;
import com.example.extenddemo.entity.JsonDemo;
import com.example.extenddemo.entity.SpElDemo;
import com.example.extenddemo.utils.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/json")
public class JsonDemoController {

    private static final Logger log = LoggerFactory.getLogger(JsonDemoController.class);

    @GetMapping("/test")
    public JsonDemo test() {
        return JsonDemo
                .builder()
                .name("test").build();
    }

    @RepeatSubmit
    @GetMapping("/repeat")
    public String repeat() throws InterruptedException {
        Thread.sleep(5000);
        return "success";
    }

    @PostMapping("/Spel")
    @SpEL(value = "#{@spelService.printLog(#demo.password)}")
    public String spel(@RequestBody SpElDemo demo){
        return String.format("demo的值为；%s", demo);
    }

    @PostMapping("/submitJson")
    public Result<String> stringResult (@RequestBody JsonDemo demo){
        log.warn("jsonDemo:{}",demo);
        return Result.Success("success");
    }
}
